package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.RemoteAcaExperimentService;
import com.ruoyi.system.api.domain.Experiment;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

@Component
public class RemoteAcaExperimentFallbackFactory implements FallbackFactory<RemoteAcaExperimentService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteLogFallbackFactory.class);
    @Override
    public RemoteAcaExperimentService create(Throwable throwable) {
        // 记录错误日志
        log.error("远程调用失败，进入降级处理", throwable.getMessage());
        System.out.println("用户调用服务失败：{}"+throwable.getMessage());
        return new RemoteAcaExperimentService() {
            @Override
            public List<Experiment> list1(Experiment experiment){
                log.error("远程调用失败，返回空列表");
                return Collections.emptyList();
            }

            @Override
            public AjaxResult getInfo(Long experimentId) {
                return AjaxResult.error("远程调用失败，返回默认值" +throwable.getMessage());
            }
        };
    }
}
